package yawning.mew.gui.characters.attributes;

import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.JSpinner;

import yawning.mew.gui.tools.CharacterDataSource;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import javax.swing.SpinnerNumberModel;

@SuppressWarnings("serial")
public class DefensesAttributes extends JPanel {
	private CharacterDataSource source; 
	private JSpinner spnArmor;
	private JSpinner spnDodge;
	private JTextPane lblDodgePerc;
	private JSpinner spnParry;
	private JTextPane textPane;
	private JSpinner spnBlock;
	private JTextPane textPane_1;
	private JSpinner spnResilience;
	private JTextPane textPane_2;
	
	/**
	 * Create the panel.
	 */
	public DefensesAttributes(CharacterDataSource source) {
		this.source = source;
		setLayout(null);
		
		JTextPane txtpnArmor = new JTextPane();
		txtpnArmor.setEditable(false);
		txtpnArmor.setText("Armor:");
		txtpnArmor.setBounds(10, 11, 79, 20);
		add(txtpnArmor);
		
		spnArmor = new JSpinner();
		spnArmor.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnArmor.setToolTipText("Armor (without bonus armor)");
		spnArmor.setBounds(99, 11, 79, 20);
		add(spnArmor);
		
		JTextPane txtpnDodge = new JTextPane();
		txtpnDodge.setEditable(false);
		txtpnDodge.setText("Dodge:");
		txtpnDodge.setBounds(10, 42, 79, 20);
		add(txtpnDodge);
		
		spnDodge = new JSpinner();
		spnDodge.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnDodge.setToolTipText("Dodge rating");
		spnDodge.setBounds(99, 42, 79, 20);
		add(spnDodge);
		
		lblDodgePerc = new JTextPane();
		lblDodgePerc.setEditable(false);
		lblDodgePerc.setToolTipText("Dodge chance");
		lblDodgePerc.setBounds(188, 42, 59, 20);
		add(lblDodgePerc);
		
		JTextPane txtpnParry = new JTextPane();
		txtpnParry.setEditable(false);
		txtpnParry.setText("Parry:");
		txtpnParry.setBounds(10, 73, 79, 20);
		add(txtpnParry);
		
		spnParry = new JSpinner();
		spnParry.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnParry.setToolTipText("Parry rating");
		spnParry.setBounds(99, 73, 79, 20);
		add(spnParry);
		
		textPane = new JTextPane();
		textPane.setEditable(false);
		textPane.setToolTipText("Parry chance");
		textPane.setBounds(188, 73, 59, 20);
		add(textPane);
		
		JTextPane txtpnBlock = new JTextPane();
		txtpnBlock.setEditable(false);
		txtpnBlock.setText("Block:");
		txtpnBlock.setBounds(10, 104, 79, 20);
		add(txtpnBlock);
		
		spnBlock = new JSpinner();
		spnBlock.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnBlock.setToolTipText("Block rating");
		spnBlock.setBounds(99, 104, 79, 20);
		add(spnBlock);
		
		textPane_1 = new JTextPane();
		textPane_1.setEditable(false);
		textPane_1.setToolTipText("Block chance");
		textPane_1.setBounds(188, 104, 59, 20);
		add(textPane_1);
		
		JTextPane txtpnResilience = new JTextPane();
		txtpnResilience.setEditable(false);
		txtpnResilience.setText("Resilience:");
		txtpnResilience.setBounds(10, 135, 79, 20);
		add(txtpnResilience);
		
		spnResilience = new JSpinner();
		spnResilience.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnResilience.setToolTipText("Resilience Rating");
		spnResilience.setBounds(99, 135, 79, 20);
		add(spnResilience);
		
		textPane_2 = new JTextPane();
		textPane_2.setEditable(false);
		textPane_2.setToolTipText("Damage reduction");
		textPane_2.setBounds(188, 135, 59, 20);
		add(textPane_2);
		initDataBindings();

	}
	protected void initDataBindings() {
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_1 = BeanProperty.create("toon.rating_Dodge");
		BeanProperty<JSpinner, Object> jSpinnerBeanProperty = BeanProperty.create("value");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_1, spnDodge, jSpinnerBeanProperty, "dodge");
		autoBinding_1.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_2 = BeanProperty.create("toon.rating_Parry");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_2 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_2, spnParry, jSpinnerBeanProperty, "parry");
		autoBinding_2.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_3 = BeanProperty.create("toon.rating_Block");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_3 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_3, spnBlock, jSpinnerBeanProperty, "block");
		autoBinding_3.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_4 = BeanProperty.create("toon.rating_Resilience");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_4 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_4, spnResilience, jSpinnerBeanProperty, "resilience");
		autoBinding_4.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_5 = BeanProperty.create("toon.armor");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_5 = Bindings.createAutoBinding(UpdateStrategy.READ, source, characterDataSourceBeanProperty_5, spnArmor, jSpinnerBeanProperty, "Armor");
		autoBinding_5.bind();
	}
}
